package com.ptswitch.material.dao.impl;

import java.util.List;

import org.hxzon.project.SpringJdbcDao;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.ptswitch.material.model.common.EMailAddress;

@Repository
public class EMailAddressDao extends SpringJdbcDao {
    private static final RowMapper<EMailAddress> emailAddressMapper = buildBeanRowMapper(EMailAddress.class);

    public List<EMailAddress> findAll() {
        String fullSql = "select id,realname,email,createTime,updateTime"//
                + " from emailAddress order by email";
        return super.queryList(fullSql, buildMapParams(), emailAddressMapper);
    }

    public void save(EMailAddress model) {
        String fullSql = null;
        model.updateTimeInfo();
        if (model.getId() == null) {
            model.setId(super.buildUuid());
            fullSql = "insert into emailAddress(id,realname,email,createTime,updateTime) "//
                    + " values(:id,:realname,:email,:createTime,:updateTime)";
        } else {
            fullSql = "update emailAddress set"//
                    + " realname=:realname,email=:email,updateTime=:updateTime";
        }
        super.execute(fullSql, buildBeanParams(model));
    }

    public void delete(String id) {
        String deleteSql = "delete emailAddress where id=:id";
        super.execute(deleteSql, buildMapParams("id", id));
    }
}
